package com.extremelylargepackage.entity;

import com.extremelylargepackage.GameResources;

public class AiAvoid implements AiMoveComponent
{
	private Enemy _me;
	private boolean _ySet;
	private static final float TOLERANCE = 5;

	@Override
	public void performMove(long time) 
	{
		if(!_ySet)
		{
			_me._dirY = GameResources.SCREEN_WIDTH * .25f;
			_ySet = true;
		}
		
		Player p = _me._player;
		boolean right = false, left = false;
		if(Math.abs(_me._player._dirX) <= TOLERANCE)
		{
			right =	p._locX + (p._sprite.getWidth() / 2f) >= GameResources.SCREEN_WIDTH / 2f; 
			left = !right;
		}
		else if(left || p._dirX > 0)
		{
			_me._dirX = 0 - _me._locX;
		}
		else if(right || p._dirX < 0)
		{
			_me._dirX = GameResources.SCREEN_WIDTH - _me._locX - _me._sprite.getWidth();
		}			
	}
	
	@Override
	public void setSelf(Enemy me) 
	{
		_me = me;	
	}

	@Override
	public boolean finished() 
	{
		return false;
	}
	
	@Override
	public Object clone()
	{
		return new AiAvoid();
	}

}
